<?php
/**
 * Created by PhpStorm.
 * User: lazycao
 * Date: 2017/12/6 0006
 * Time: 11:02
 */

namespace Home\Controller;


class LoginController extends HomeController
{
    function index(){
        $this->display('login');
    }
    function doLogin(){
        $user_name = trim(I('post.username'));
        $password = I('post.password');
        if(empty($user_name) || empty($password)){
            $this->error('参数错误');
        }
        $pass = M('Admin')->where(array('user_name'=>$user_name))->getField('password');
        if(!$pass){
            $this->error('用户不存在');
        }
        if(md5($password) !== $pass){
            $this->error('密码错误');
        }
        session('user_auth',$user_name);
        redirect(U('Admin/index'));

    }
    function logOut(){
        session('user_auth',null);
        redirect(U('Login/index'));
    }
}